package com.woniu.zsd.waste.controller;


import com.github.pagehelper.*;
import com.woniu.zsd.commons.core.model.Result;
import com.woniu.zsd.permission.Permission.Permission;
import com.woniu.zsd.waste.entity.WasteType;
import com.woniu.zsd.waste.service.IWasteTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zsd.waste.form.AddWasteTypeForm;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-27
 */
@RestController
@RequestMapping("/waste-type")
@Api(tags = "废品类型管理")
public class WasteTypeController {

    @Autowired
    private IWasteTypeService wasteTypeService;

    @GetMapping("/selWasteType")
    @ApiOperation("查询所有废品类型")
    public Result<List<WasteType>> selWasteType() {
        List<WasteType> wasteType = wasteTypeService.selWasteType();
        return new Result< List<WasteType>>().setData(wasteType).setCode(200).setMsg("查询成功");
    }

    @PutMapping("/insertWasteType")
    @ApiOperation("新增废品类型")
    @Permission("insertWasteType")
    public Result<Integer> insertWasteType(AddWasteTypeForm awtf,@RequestHeader String token) {
        int result = wasteTypeService.insertWasteType(awtf);
        return new Result<Integer>().setData(result).setCode(200).setMsg("新增成功");
    }

    @PostMapping("/updateWasteType")
    @ApiOperation("修改废品类型")
    @Permission("updateWasteType")
    public Result<Integer> updateWasteType(@RequestBody WasteType wasteType,@RequestHeader String token) {
        int result = wasteTypeService.updateWasteType(wasteType);
        return new Result<Integer>().setData(result).setCode(200).setMsg("修改成功");
    }

    @DeleteMapping("/deleteWasteType/{id}")
    @ApiOperation("删除废品类型")
    @Permission("deleteWasteType")
    public Result<Integer> deleteWasteType(@PathVariable Integer id,@RequestHeader String token) {
        int result = wasteTypeService.deleteWasteType(id);
        return new Result<Integer>().setData(result).setCode(200).setMsg("删除成功");
    }

    @GetMapping("/getWasteTypeById/{id}")
    @ApiOperation("根据ID查询废品类型")
    public Result<WasteType> getWasteTypeById(@PathVariable Integer id) {
        WasteType wasteType = wasteTypeService.getWasteTypeById(id);
        return new Result<WasteType>().setData(wasteType).setCode(200).setMsg("查询成功");
    }

    @GetMapping("/getWasteTypeByName/{name}")
    @ApiOperation("根据名称查询废品类型")
    public Result<WasteType> getWasteTypeByName(@PathVariable String name) {
        WasteType wasteType = wasteTypeService.getWasteTypeByName(name);
        return new Result<WasteType>().setData(wasteType).setCode(200).setMsg("查询成功");
    }
    @GetMapping("/getTop5SearchedWasteTypes")
    @ApiOperation("查询热点废品类型")
    public Result<List<WasteType>> getTop5SearchedWasteTypes() {
        List<WasteType> top5WasteTypes = wasteTypeService.getTop5SearchedWasteTypes();
        return new Result<List<WasteType>>().setData(top5WasteTypes).setCode(200).setMsg("查询成功");
    }
}
